package com.pignest.hotel.definition;

import com.pignest.hotel.beans.Room;

/** 
 * 房间使用状态
 * */
public enum RoomUseStatus {
	
	CLEAN("干净", "white.png")
	, DIRTY("赃", "dirty.png")
	, EMPTY_NIGHT("空隔夜", "emptyNight.png")
	, CHECKING("整理", "tidy.png")
	;
	
	private String cname;
	private String icon;
	public final static RoomUseStatus DEFAULT = CLEAN;

	RoomUseStatus(String cname, String icon){
		this.cname = cname;
		this.icon = icon;
	}
	
	public String getName() {
		return cname;
	}
	
	public String getImage() {
		return icon;
	}
	
	public boolean is(Room room) {
		return room != null && name().equals(room.getUseStatus());
	}
	
	/////////////////////////////////////////////////////////////////////////////////////
	
	public static RoomUseStatus getByCName(String cname) {
		RoomUseStatus[] values = RoomUseStatus.values();
		for (int i = 0; i < values.length; i++) {
			if (values[i].cname.equals(cname))
				return values[i];
		}
		return DEFAULT;
	}
	
	/** no exception version of {@link #valueOf(String)} */
	public static RoomUseStatus valueof(String name) {
		try {
			return RoomUseStatus.valueOf(name);
		} catch (RuntimeException e) {//IllegalArgumentException, NullPointerException
		}
		return null;
	}
	
	public static String[] names() {
		RoomUseStatus[] values = RoomUseStatus.values();
		String[] r = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			r[i] = values[i].name();
		}
		return r;
	}
	
	public static String[] cnames() {
		RoomUseStatus[] values = RoomUseStatus.values();
		String[] r = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			r[i] = values[i].cname;
		}
		return r;
	}
}
